import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { JCronValidator } from '/@/components/Form';

export const columns: BasicColumn[] = [
  {
    title: '任务名称',
    dataIndex: 'taskName',
  },
  {
    title: '源数据源',
    dataIndex: 'sourceDataSourceId_dictText',
  },
  {
    title: '单位',
    dataIndex: 'unitId_dictText',
  },
  {
    title: '财务系统类型',
    dataIndex: 'accountingSystem_dictText',
  },
  {
    title: 'Cron表达式',
    dataIndex: 'cronExpression',
  },
  {
    title: '年度',
    dataIndex: 'year_dictText',
  },
  {
    title: '目标数据源',
    dataIndex: 'targetDataSourceId_dictText',
  },
  {
    title: '备注',
    dataIndex: 'remark',
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 100,
    customRender: ({ text }) => {
      const color = text == '0' ? 'green' : text == '-1' ? 'red' : 'gray';
      return render.renderTag(render.renderDict(text, 'quartz_status'), color);
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: "taskName",
    label: "任务名称",
    component: 'Input',
    colProps: {
      span: 6
    }
  },
  {
    field: 'status',
    label: '任务状态',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'quartz_status',
      stringToNumber: true,
    },
    colProps: {
      span: 6
    }
  },
  {
    field: 'accountingSystem',
    label: '财务系统类型',
    component: "DictSelect",
    componentProps: {
      dictCode: "accounting_system",
    },
    colProps: {
      span: 6
    },
  },
  {
    field: 'sourceDataSourceId',
    label: '源数据源',
    component: "DataSourceSelect",
    colProps: {
      span: 6
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: "taskName",
    label: "任务名称",
    component: 'Input',
    required: true,
  },
  {
    field: 'sourceDataSourceId',
    label: '源数据源',
    component: "DataSourceSelect",
    required: true,
  },
  {
    field: "unitId",
    titleField: "unitId_dictText",
    label: "单位",
    component: 'UnitSelect',
  },
  {
    field: 'accountingSystem',
    label: '财务系统类型',
    component: "DictSelect",
    required: true,
    componentProps: {
      dictCode: 'accounting_system'
    }
  },
  // {
  //   field: 'jobClassName',
  //   label: '任务类名',
  //   component: 'Input',
  //   required: true,
  // },
  {
    field: 'year',
    label: '年度',
    component: 'DictSelect',
    componentProps: {
      dictCode: 'cwqs_year',
      mode: 'multiple',
    },
    required: true
  },
  {
    field: 'month',
    label: '月份',
    component: 'DictSelect',
    componentProps: {
      dictCode: 'month',
      mode: 'multiple',
      maxTagCount: 4,
      selectAll: true
    },
    required: true
  },
  {
    field: 'targetDataSourceId',
    label: '目标数据源',
    component: "DataSourceSelect",
    required: true,
  },
  {
    field: 'cronExpression',
    label: 'Cron表达式',
    component: 'JEasyCron',
    defaultValue: '* * * * * ? *',
    rules: [{ required: true, message: '请输入Cron表达式' }, { validator: JCronValidator }],
  },
  // {
  //   field: 'paramterType',
  //   label: '参数类型',
  //   component: 'Select',
  //   defaultValue: 'string',
  //   componentProps: {
  //     options: [
  //       { label: '字符串', value: 'string' },
  //       { label: 'JSON对象', value: 'json' },
  //     ],
  //   },
  // },
  // {
  //   field: 'parameter',
  //   label: '参数',
  //   component: 'InputTextArea',
  //   ifShow: ({ values }) => {
  //     return values.paramterType == 'string';
  //   },
  // },
  // {
  //   field: 'parameter',
  //   label: '参数',
  //   component: 'JAddInput',
  //   helpMessage: '键值对形式填写',
  //   ifShow: ({ values }) => {
  //     return values.paramterType == 'json';
  //   },
  // },
  {
    field: 'status',
    label: '状态',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'quartz_status',
      type: 'radioButton',
      stringToNumber: true,
      dropdownStyle: {
        maxHeight: '6vh',
      },
    },
  },
  {
    field: 'remark',
    label: '描述',
    component: 'InputTextArea',
  },
];
